package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ErrorCode;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.CustomerReturnList;
import com.atguigu.jxc.service.CustomerReturnListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * 客户退货
 */
@RestController
@RequestMapping("/customerReturnListGoods")
public class CustomerReturnListGoodsController {

    @Autowired
    private CustomerReturnListGoodsService customerReturnListGoodsService;

    //http://localhost:8080/customerReturnListGoods/save?returnNumber=XT1605772786495（退货单号）
    //客户退货单保存
    @PostMapping("/save")
    public ServiceVO save(CustomerReturnList customerReturnList, String customerReturnListGoodsStr, HttpSession session){
        try {
            customerReturnListGoodsService.save(customerReturnList,customerReturnListGoodsStr,session);
            return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new ServiceVO(ErrorCode.PARA_TYPE_ERROR_CODE,ErrorCode.PARA_TYPE_ERROR_MESS);
        }
    }

    //http://localhost:8080/customerReturnListGoods/list
    //客户退货单查询（可查询条件：退货单号、客户、退款状态）
    @PostMapping("/list")
    public Map<String,Object> list(String returnNumber, Integer customerId, Integer state, String sTime,String eTime){
        return customerReturnListGoodsService.list(returnNumber,customerId,state,sTime,eTime);
    }

    //http://localhost:8080/customerReturnListGoods/goodsList
    //退货单商品信息  Integer customerReturnListId
    @PostMapping("/goodsList")
    public Map<String,Object> goodsList(Integer customerReturnListId){
        return customerReturnListGoodsService.goodsList(customerReturnListId);
    }

    //http://localhost:8080/customerReturnListGoods/delete
    //删除退货单 Integer customerReturnListId
    @PostMapping("/delete")
    public ServiceVO delete(Integer customerReturnListId){
        try {
            customerReturnListGoodsService.delete(customerReturnListId);
            return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new ServiceVO(ErrorCode.PARA_TYPE_ERROR_CODE, ErrorCode.PARA_TYPE_ERROR_MESS);
        }
    }

    //http://localhost:8080/customerReturnListGoods/updateState
    //支付结算（修改客户退货单退款状态） Integer customerReturnListId
    @PostMapping("/updateState")
    public ServiceVO updateState(Integer customerReturnListId){
        ServiceVO   serviceVO=customerReturnListGoodsService.updateState(customerReturnListId);
        return serviceVO;
    }

    //http://localhost:8080/customerReturnListGoods/count
    //客户退货统计（可根据 商品类别、商品编码或名称 条件查询）
    @PostMapping("/count")
    public String count(String sTime, String eTime, Integer goodsTypeId, String codeOrName){
        return customerReturnListGoodsService.count(sTime,eTime,goodsTypeId,codeOrName);
    }
}
